package edu.um.variable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ArrayVariable extends Variable {

  private final List<Range> ranges;

  private VariableType subType = null;

 private final Map<List<Integer>, Object> values = new HashMap<List<Integer>, Object>();

  public ArrayVariable(String name, VariableType theSubType, List<Range> theRanges) {
    super(name, VariableType.ARRAY);
    if (theRanges == null || theRanges.size() == 0) {
      throw new IllegalArgumentException(
          "Array variable must have at least one range");
    }
    ranges = new ArrayList<Range>();
    for (Range range : theRanges) {
      ranges.add(range);
    }
    subType = theSubType;
  }

  public VariableType getSubType() {
    return subType;
  }

  public List<Range> getRanges() {
    return ranges;
  }

  public void setValueAt(List<Integer> indexes, Object value) {
    values.put(indexes, value);
  }
  public Object getValueAt(List<Integer> indexes) {
    return values.get(indexes);
  }

  public boolean hasValueAt(List<Integer> indexes) {
    return values.containsKey(indexes);
  }
}
